package hu.bme.orarend.client;

import hu.bme.orarend.shared.ClassDTO;
import hu.bme.orarend.shared.RoomDTO;

import java.util.List;

import org.gwt.advanced.client.datamodel.EditableGridDataModel;
import org.gwt.advanced.client.ui.widget.GridPanel;
import org.gwt.advanced.client.ui.widget.cell.LabelCell;

public class ClassGridPanel extends GridPanel
{
  private String[][] data = new String[1][1];
  EditableGridDataModel editableGridDataModel = new EditableGridDataModel( data );

  public void createClassGrid()
  {
    this.createEditableGrid( new String[] { "Azonosító", "Név", "Leírás", "Tanár", "Teremtípus", "Nap", "Kezdési idő", "Befejezési idő", "Létszám", "Projektor", "Erősítő", "Fix terem" },
                             new Class[] { LabelCell.class, LabelCell.class, LabelCell.class, LabelCell.class, LabelCell.class, LabelCell.class, LabelCell.class, LabelCell.class, LabelCell.class, LabelCell.class, LabelCell.class, LabelCell.class },
                             editableGridDataModel );
    this.getGrid().enableVerticalScrolling( true );
    this.getGrid().setBodyHeight( "150px" );
    this.setBottomPagerVisible( false );
    this.setTopPagerVisible( false );
    this.setBottomToolbarVisible( false );
    this.setTopToolbarVisible( false );
    this.setHeight( "100px" );
    this.display();
  }
  
  public void refreshData( List<ClassDTO> classList )
  {
    this.unlock();
    data = new String[classList.size()][12];
    int i = 0;
    for( ClassDTO classDTO:classList )
    {
      data[i][0] = String.valueOf( classDTO.getId() );
      data[i][1] = classDTO.getName();
      data[i][2] = classDTO.getDescription();
      data[i][3] = classDTO.getTeacher();
      data[i][4] = ("0".equals( classDTO.getRoomType()))?(RoomDTO.TYPE_0):(RoomDTO.TYPE_1);
      data[i][5] = classDTO.getDay();
      data[i][6] = classDTO.getStart();
      data[i][7] = classDTO.getEnd();
      data[i][8] = String.valueOf( classDTO.getNumber() );
      data[i][9] = ((classDTO.isProjector() == true)?RoomDTO.YES:RoomDTO.NO);
      data[i][10] = ((classDTO.isAmplifier() == true)?RoomDTO.YES:RoomDTO.NO);
      data[i][11] = classDTO.getRoom();
      
      i++;
    }
    editableGridDataModel.update( data );
    this.lock();
    this.adjust();
  }
}
